package com.example.administrator.xiaobo.adapter.show_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.bean.show_3_itemBean;

import java.util.LinkedList;
import java.util.Random;

/**
 * Created by Administrator on 2017/2/8.
 * viewType=3 各种字体
 */

public class ShowAdapter2 extends RecyclerView.Adapter<ShowAdapter2.MyViewHolder> {
    private Context context;
    private LinkedList<show_3_itemBean> data;
    private Random random;
    private int[]colors;

    public ShowAdapter2(Context context, LinkedList<show_3_itemBean> data) {
        this.context = context;
        this.data = data;
        colors = new int[]{0xFF000000, 0xFF444444, 0xFF888888, 0xFFCCCCCC, 0xFFFF0000
                , 0xFF00FF00, 0xFF0000FF, 0xFFFFFF00, 0xFF00FFFF, 0xFFFF00FF};
        random = new Random();
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_show_0102,null);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.textView.setText(data.get(position).tag);
        //设置字体的大小和颜色
        holder.textView.setTextColor(colors[random.nextInt(colors.length)]);
        if (data.get(position).tag.length()>=3) {
            holder.textView.setTextSize(10+random.nextInt(10));
        }else if(data.get(position).tag.length()==1){
            holder.textView.setTextSize(15+random.nextInt(20));
        }else
            holder.textView.setTextSize(10+random.nextInt(20));
    }

    @Override
    public int getItemCount() {
        return 10;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        TextView textView;
        public MyViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.textView_show0102);
        }
    }
}
